package com.project.mvprxsample.ui;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.project.mvprxsample.R;
import com.project.mvprxsample.bean.NetworkErrorBean;
import com.project.mvprxsample.bean.TestDB;
import com.project.mvprxsample.bean.UserInfo;
import com.project.mvprxsample.presenters.UserPresenter;
import com.project.mvprxsample.ui.activity.BaseActivity;
import com.project.mvprxsample.ui.activity.FragmentTestActivity;
import com.project.mvprxsample.view.BaseView;

import org.json.JSONObject;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends BaseActivity implements BaseView<UserInfo> {

    @BindView(R.id.text)
    TextView textView;
    @BindView(R.id.text2)
    TextView textView2;
    @BindView(R.id.text3)
    TextView textView3;
    @BindView(R.id.text4)
    TextView textView4;
    UserPresenter userPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    /**
     * 初始化标题栏
     */
    @Override
    protected void initTitle() {
        setTitle("测试");
    }

    /**
     * 初始化控件
     */
    @Override
    protected void initView() {
        ButterKnife.bind(this);
    }

    /**
     * 初始化presenters
     */
    @Override
    protected void initPresenters() {
        userPresenter = new UserPresenter(this, this);
    }

    /**
     * 点击menu菜单事件
     *
     * @return
     */
    @Override
    protected void doActionMenu() {

    }

    @Override
    protected boolean hideActionBar() {
        return false;
    }

    @Override
    protected Drawable getActionMenuIcon() {
        return null;
    }

    @Override
    protected String getActionMenuText() {
        return null;
    }


    @OnClick(R.id.text)
    public void textOnclick() {
        userPresenter.saveUserInfo("张三", "18576600881");
        userPresenter.saveUserInfo("张四", "13781927993");
        userPresenter.saveUserInfo("张五", "18576688881");
    }

    @OnClick(R.id.text2)
    public void textOnclick2() {
        List<TestDB> list = userPresenter.getUserInfoByUserName("张四");
        for (TestDB userInfo : list) {
            Toast.makeText(this, userInfo.getUSER_NAME(), Toast.LENGTH_SHORT).show();
        }
    }

    @OnClick(R.id.text3)
    public void textOnclick3() {
//        userPresenter.deleteByUserName("张五");
//        userPresenter.userLogin("lvyang","Ff123456");

        userPresenter.resultJSON(userPresenter.mBaseApi.login("lvyang","Ff123456") , this, "aa");
    }

    @OnClick(R.id.text4)
    public void textOnclick4() {
        Intent intent = new Intent(mContext, FragmentTestActivity.class);
        startActivity(intent);
    }


    @Override
    public void getSuccess(UserInfo userInfo, String tag) {



    }

    @Override
    public void getFail(NetworkErrorBean bean , String tag) {

    }

    @Override
    public void onCompleted(String tag) {

    }
}
